#pragma once

#include <linux/types/mm.h>
#include <linux/printk.h>
#include <linux/pgtable.h>
#include <linux/stddef.h>
#include <linux/gfp_types.h>

#define VM_MIXEDMAP 0x10000000   /* Can contain "struct page" and pure PFN pages */
#define VM_HUGEPAGE 0x20000000   /* MADV_HUGEPAGE marked this vma */
#define VM_NOHUGEPAGE 0x40000000 /* MADV_NOHUGEPAGE marked this vma */
#define VM_MERGEABLE 0x80000000  /* KSM may merge identical pages */

#define VM_PFNMAP 0x00000400  /* Page-ranges managed without "struct page", just pure PFN */
#define VM_UFFD_WP 0x00001000 /* wrprotect pages tracking */

int vm_insert_page(struct vm_area_struct *, uintptr_t addr, struct page *);

static inline unsigned long vma_pages(struct vm_area_struct *vma)
{
    return (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
}

static inline void vm_flags_set(struct vm_area_struct *vma,
                                vm_flags_t flags)
{
    pr_todo();
}

#define pte_unmap_unlock(pte, ptl) \
    do                             \
    {                              \
        spin_unlock(ptl);          \
        pte_unmap(pte);            \
    } while (0)
